<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}

if(isset($_REQUEST['Submit']) && ($_REQUEST['Submit'])=="Submit")
{
	if(isset($_REQUEST['intid']) && ($_REQUEST['intid'])!="")
	{
	$id=mysql_real_escape_string($_REQUEST['intid']);
	$sql="select * from tblcontact where intid='$id'";
		$result=$obj_db->select($sql);
  		if($result)
		{
			$email=$result[0]['varemail'];
			
		}	
	}
	$mail_subject="Response to your contact form from ".SITENAME;
	$mess=$_REQUEST['reply'];
	$message=$mess;

$headers = "From:".FROMEMAIL;
//echo $recive;
	mail($email, $mail_subject, $message, $headers);
	if(isset($_SESSION['adminuserid']) && $_SESSION['adminuserid']!="")
	{
	$adminid=$_SESSION['adminuserid'];
	}
	$sql_upd="update tblcontact set `intsentby`=$adminid,`varreply`='YES' where intid='$id'";
	$upd=$obj_db->edit($sql_upd);
	header("location:contactus.php?msg=reply");
	die();
}

//DELETE record from database
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{	
		$id =  mysql_real_escape_string($_REQUEST['intid']);
		$sql= "DELETE FROM `tblcontact` WHERE `intid` ='$id'";
		$query1 = mysql_query($sql);
		
		header("location:contactus.php?msg=del");
		die();
	}
}


?>
<?php include("inc/header.php");?>
<body>
<script language="javascript" src="js/currency.js"></script>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td align="center"><?php   
  
	if(isset($_REQUEST['intid']) && ($_REQUEST['intid'])!="")
	
	{
		$sql="select * from tblcontact where intid=".mysql_real_escape_string($_REQUEST['intid']);
		$result=$obj_db->select($sql);
  		if($result)
		{
			$email=$result[0]['varemail'];
	?>
		<form action="" method="post" enctype="multipart/form-data" name="currency">
		  
		  <table width="60%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
		    <tr class="bg1">
		      <td colspan="5" align="center">Reply</td>
          </tr>
		    <tr>
		      <td>&nbsp;</td>
            <td align="left">&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right">&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
		    <tr>
		      <td width="2%">&nbsp;</td>
            <td width="30%" align="left" class="sltimg"><strong>Name </strong></td>
            <td width="3%">:</td>
            <td width="56%" align="left"><label><?php echo stripslashes($result[0]['varname']);?></label></td>
            <td width="9%">&nbsp;</td>
          </tr>
		    <tr>
		      <td>&nbsp;</td>
            <td align="left" class="sltimg"><strong>E-mail </strong></td>
            <td>:</td>
            <td align="left"><?php echo stripslashes($result[0]['varemail']);?></td>
            <td>&nbsp;</td>
          </tr>
		    <tr>
		      <td>&nbsp;</td>
            <td align="left" class="sltimg"><strong>Message </strong></td>
            <td>:</td>
            <td align="left" class="mess"><?php echo stripslashes($result[0]['txtmess']);?></td>
            <td>&nbsp;</td>
          </tr>
		    
		    <tr>
		      <td align="left">&nbsp;</td>
            <td align="left"><strong>Reply</strong></td>
            <td align="left">:</td>
            <td align="left"><textarea name="reply" id="reply"></textarea></td>
            <td align="left">&nbsp;</td>
          </tr>
		    <tr>
		      <td colspan="5" align="center"><input name="Submit" type="submit" class="btn" id="Submit" value="Submit" onClick="return check();"/></td>
          </tr>
		    <tr>
		      <td colspan="5" align="center">&nbsp;</td>
          </tr>
	      </table> </form>
      <?php
	}
}
else
{
?>
  <br />
		  <br />
		  
		  <table width="70%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
		    <tr class="bg1">
		      <td height="18" colspan="8" align="left"><strong >Inquiry  List... </strong>&nbsp;&nbsp;</td>
            </tr>
		    <tr align="center">
		      <?php
	   $rows="";
	 if(isset($_REQUEST['page']) && ($_REQUEST['page'])!="")
	 {
	 	$rows=$_REQUEST['page'];
	 
	  }	
	  ?><form name="form1" action="" method="post">
              <td colspan="2" align="left">
			  
			  Row per Page:
                <select name="page" onChange="document.form1.submit();">
                  <option value="0"<?php if($rows=='0'){echo "selected";}else{echo "";}?>>All</option>
                  <option value="5"<?php if($rows=='5'){echo "selected";}else{echo "";}?>>5 Per Page</option>
                  <option value="10"<?php if($rows=='10'){echo "selected";}else{echo "";}?>>10 Per Page</option>
                  <option value="15"<?php if($rows=='15'){echo "selected";}else{echo "";}?>>15 Per Page</option>
                </select>
				
				</td>
				</form>
	        </tr>
		    <tr align="center" class="tblbg3">
		      <td class="tblbg3">Name</td>
              <td class="tblbg3">Email</td>
              <td class="tblbg3">Phone</td>
			   <td class="tblbg3">Message</td>
			   <td class="tblbg3">Replied?</td>
			   <td class="tblbg3">Send Reply</td>
			   <td class="tblbg3">Reply By</td>
              <td>Delete</td>
            </tr>
		    <?php
	  
	  /**************************************
				PAGING CODE START
		**************************************/
			if(isset($_REQUEST['page']) && ($_REQUEST['page'])!=0)
			{
				$rows=$_REQUEST['page'];
				$rowperpage=$rows;
			}else{$rowperpage=$rows=10000;}
			
			$tablename="tblprodcategory";
			$per_page_keywords= "";
			$per_page_sorts="";
			include("system/paging.inc.php");

		/**************************************
				PAGING CODE ENDING
		**************************************/
	  
	  
		?>
		    <?php
   		$sql="select * from tblcontact Limit ".($page_no*$row_per_page).",".$row_per_page;
		$result=$obj_db->select($sql);
  		if($result)
		{
   		for($i=0;$i<count($result);$i++)
   		{
            $id=$result[$i]['intid'];
			//$imagepath = "../images/manuf/";
			//$limit=$result[$i]['varimagepath'];
			//$imagename = $imagepath.$limit;
			?>
		    <tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onMouseOut="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
		      <td align="center"><?php echo $result[$i]['varname'];?></td>
              <td align="center"><?php echo $result[$i]['varemail'];?></td>
              <td align="center"><?php echo $result[$i]['varphone'];?></td>
			  <td align="center"><?php
			
			  //$desctxt=$sql[$j]['vartext'];
				$desc=$result[$i]['txtmess'];
				if(strlen($desc) > 10 )
				{
				$desc=substr($desc,0,10); 
				$desc=$desc."...";
				//echo $desctxt;
				}
				echo $desc;

			  
			  ?></td>
			 <td align="center"><?php if ($result[$i]['varreply'] == "YES") { echo "YES"; } else { echo "NO"; } ;?></td> 
			<td align="center"><a class="aa" href="contactus.php?intid=<?php echo $id?>">Reply</a></td>
			<td align="center">
			<?php 
			$id=$result[$i]['intsentby'];
			$sqladmin="select `varadminfname` from tbladmin where intid='$id'";
			$resadmin=$obj_db->select($sqladmin);
			if($resadmin)
			{
				echo $resadmin[0]['varadminfname'];
			}
			?></td> 
              <td align="center"><a Title="Click here to Delete" href="contactus.php?a=3&amp;intid=<?php echo $result[$i]['intid']; ?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
            </tr>
		    <?php }}?>
	      </table>
		  <?php }?>
   </td>
  </tr>
  <tr>
    <td><?php include("inc/bottom.php");?></td>
  </tr>
</table>
</body>
</html>

